<template>
	<view class="container">
		<u-top-tips ref="uTips" :navbar-height="44"></u-top-tips>
		<u-navbar back-text="" back-icon-color="#fff" title="申请信息" title-color="#fff" :background="{ background: '#3669f8' }" :custom-back="()=>{
			vk.navigateTo('/pages/index/index')}"></u-navbar>
		<view class="header">
			<view>
				<text class="sub">
					请完善以下申请信息！
				</text>
			</view>
			<view>
				<text class="info">为了申请顺利通过，请上传真实有效，且清晰明确的材料</text>
			</view>
		</view>
		<view class="list_box">
			<view class="list_1"  @click="navKunnan">
				<image src="../../static/modular.png" mode=""></image>
				<view class="list_1_text">
					<text>家庭基本情况</text>
					<text class="list_1_text_info">请认真填写家庭基本情况</text>
				</view>

				<u-button  @click="navKunnan" :disabled="editBtnbis" :type="btnKunnan?'primary':'error'" :plain="!btnKunnan" class="btn" style="margin-left: 70rpx;padding: 30rpx;font-size: 13px" shape="circle" size="mini">
					{{btnKunnanText}}
					</u-button>
			</view>
			
			
			<view class="list_1" @click="navCatch" v-if="vk.getVuex('$app.isKunnan')">
				<image src="../../static/modular.png" mode=""></image>
				<view class="list_1_text">
					<text>家庭经济信息采集</text>
					<text class="list_1_text_info">请认真填写家庭经济信息</text>
				</view>
	
				<u-button  @click="navCatch" :disabled="editBtnbis" :type="btnCatch?'primary':'error'" :plain="!btnCatch" class="btn" style="margin-left: 70rpx;padding: 30rpx;font-size: 13px" shape="circle" size="mini">
					{{btnCatchText}}
					</u-button>
					
			</view>
			
			<view class="list_1" @click="navUpLoad"    v-show="btnCatch && vk.getVuex('$app.isKunnan')">
				<image src="../../static/modular.png" mode=""></image>
				<view class="list_1_text">
					<text>证明材料</text>
					<text class="list_1_text_info">请认上传真实有效的材料</text>
				</view>
				

				<u-button  @click="navUpLoad" :disabled="editBtnbis" :type="catchUpLoad?'primary':'error'" :plain="!catchUpLoad" class="btn" style="margin-left: 70rpx;padding: 30rpx;font-size: 13px" shape="circle" size="mini">
					{{catchUpLoadText}}
					</u-button>
			</view>
		</view>
		
		<view class="sub_btn">
			<button style="border-radius: 14rpx;" :type="btnDis?'default':'primary'" :disabled="btnDis" @click="submit">{{subBtn}}</button>
		</view>
		
		<view class="footer">
			<view @click="navMyApply" class="btn">
				<text >我的申请</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {submit,checkSubmitStatus} from "@/api/kunnan.js"
	import {getCatchInfo} from "@/api/catch.js"	
	var that;// 当前页面对象
	var vk; //vk依赖
	export default {
		data(){
			return {
				subBtn:'提交申请',
				stuId:'',
				btnKunnanText:'去完善',
				btnCatchText:'去完善',
				catchUpLoadText:'去完善'
			}
		},
		onLoad(options) {
			that = this;
			vk = that.vk
			that.options = options
			this.stuId = uni.getStorageSync('stuId')
			
			
		},
		
		onShow() {
			this.checkSubmitStatus()
		},
		methods:{
			navMyApply(){
				vk.navigateTo('/pages/applyList/applyList');
			},
			submit(){
				
				submit().then((data)=>{
					let [err,res] = data
					if(res.data.code == 200){
						vk.setVuex('$app.isSubmit',false)
						vk.toast('提交成功','success');
						this.btnKunnanText = '查看'
						this.btnCatchText = '查看'
						this.catchUpLoadText = '查看' 
						
						//延迟跳转
						setTimeout(()=>{
							vk.navigateTo('/pages/applyList/applyList');
						},800)
						
					}
					else {
						vk.alert(res.data.msg || err);
					}
					
				})
			},
			
			// 获取当前申请状态
			checkSubmitStatus(){
				checkSubmitStatus().then((data)=>{
					let [err,res] = data
					
					//判断家庭困难跟采集按钮状态
					if(res.data.data.kunnanInfo == "0"){
						vk.setVuex('$app.isKunnan',true)
						this.btnKunnanText = '去修改'
						
					}else {
						vk.setVuex('$app.isKunnan',false)
						this.btnKunnanText = '去完善'
						
						
					}
					
					if(vk.getVuex('$app.catchUpload')){
						this.catchUpLoadText = '去修改'
					}else {
						this.catchUpLoadText = '去完善'
					}
					
					if(res.data.data.catchInfo == "0"){
						vk.setVuex('$app.isCatch',true)
						this.btnCatchText = '去修改'
					}else {
						vk.setVuex('$app.isCatch',false)
						this.btnCatchText = '去完善'
					}
					
					//判断申请记录状态
					if(res.data.data.status == 1){
						//申请通过状态
						// 写入状态到vuex
						vk.setVuex('$app.isSubmit',false)
						this.subBtn = '申请已通过'
						this.btnKunnanText = '查看'
						this.btnCatchText = '查看'
						this.catchUpLoadText = '查看' 
					}
					else if(res.data.data.status == 0){
						//申请已提交
						vk.setVuex('$app.isSubmit',false)
						
						this.btnKunnanText = '查看'
						this.btnCatchText = '查看'
						this.catchUpLoadText = '查看' 

						this.subBtn = '申请已提交'
					}else if(res.data.data.status == 3){
						//未申请
						vk.setVuex('$app.isSubmit',true)
						this.subBtn = '提交申请'
					}
					else if(res.data.data.status == -1){
						//无申请记录
						vk.setVuex('$app.isSubmit',false)
						this.subBtn = '提交申请'
					}
					else if(res.data.data.status == 2){
						//驳回
						vk.setVuex('$app.isSubmit',false)
						this.subBtn = '申请驳回'
						this.$refs.uTips.show({
							title: '申请驳回，请到‘我的申请’页面查看驳回原因后修改提交',
							type: 'warning',
							duration: '5000'
						})
					}
					else {
						// 未知
						// vk.setVuex('$app.isSubmit',false)
						// vk.setVuex('$app.isEdit',false)
						this.subBtn = '状态错误'
					}
				})
			},

			navCatch(){
				if(!this.editBtnbis){
					vk.navigateTo('/pages/catch/catch');
				}
				
			},
			navUpLoad(){
				if(!this.editBtnbis){
					vk.navigateTo('/pages/catch/upLoad');
				}
				
			},
			navKunnan(){
				if(!this.editBtnbis){
					vk.navigateTo('/pages/pyp/kunnan');				
				}
				
			}
		},
		computed:{
			// 状态不可修改禁用按钮
			editBtnbis(){
				return !vk.getVuex('$app.isEdit')
			},
			//根据状态返回提交按钮文本
			//是否已采集
			btnCatch(){
				
				return vk.getVuex('$app.isCatch')
				
			},
			// 证明材料是否完善
			catchUpLoad(){
				
				return vk.getVuex('$app.catchUpload')
			},
			btnKunnan(){
				
				return vk.getVuex('$app.isKunnan')
			},
			isSubmit(){
				return vk.getVuex('$app.isSubmit')
			},
			//申请信息未完善禁用按钮
			btnDis(){
				if(this.isSubmit&&this.catchUpLoad&&this.btnCatch){
					return false
				}
				return true
			}
			
		}
	}
</script>

<style scoped lang="scss">
	.container {
		padding: 20rpx;
		.header {
			.sub {
				font-weight: 700;
				font-size: 18px;
			}
			.info {
				color: #888888;
				font-size: 14px;
			}
		}
		.list_box {
			padding: 10rpx;
			.list_1 {
				margin-top: 40rpx;
				padding: 20rpx;
				display: flex;
				align-items: center;
				border-radius: 20rpx;
				border: 1px solid #eeeeee;
				image {
					margin-left: 14rpx;
					width: 50rpx;
					height: 50rpx;
				}
				.list_1_text {
					margin-left: 40rpx;
					display: flex;
					flex-direction: column;
					.list_1_text_info{
						font-size: 14px;
						color: #888888;
					}
					/deep/ .btn {
						border-radius: 50rpx; 
					}
				}
			}
		}
		.sub_btn {
			margin-top: 50rpx;
			padding: 20rpx;
		}
		.footer {
			
			margin-top: 100rpx;
			display: flex;
			justify-content: center;
			.btn {
				padding: 30rpx;
			}
			text{
				color: #2979ff;
				
				
			}
			text:active{
				background-color: #cccccc;
				
			}
		}
	}
</style>
